using System;
using System.IO;
using System.Text;

namespace IceDog.Lib.IO
{
    public static class DhFileWriter
    {
        public static void WriteFile(string filename,string content)
        {
            byte[] byteData;
            char[] charData;
            try
            {
                FileStream fileStream = new FileStream(filename, FileMode.Create);
                charData = content.ToCharArray();
                byteData = new byte[charData.Length];
                Encoder encoder = Encoding.UTF8.GetEncoder();
                encoder.GetBytes(charData, 0, charData.Length, byteData, 0, true);
                fileStream.Seek(0, SeekOrigin.Begin);
                fileStream.Write(byteData, 0, byteData.Length);

            }
            catch (IOException e)
            {
                Console.WriteLine("IOException");
                Console.WriteLine(e.ToString());
                Console.ReadKey();
                throw;
            }
        }
    }
}
